package net.youpo.Market.db;

import net.youpo.Market.db.HomePage.HomeHottestTable;
import net.youpo.Market.db.HomePage.HomeNewestTable;
import net.youpo.Market.db.HomePage.HomeRecommendTable;
import net.youpo.Market.db.Ranking.RankingAllTable;
import net.youpo.Market.db.Ranking.RankingAppTable;
import net.youpo.Market.db.Ranking.RankingGameTable;
import net.youpo.Market.db.Type.TypeAllTable;
import net.youpo.Market.db.Type.TypeAppTable;
import net.youpo.Market.db.Type.TypeGameTable;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper {

    public DatabaseHelper(Context context, String name, CursorFactory factory,
            int version) {
        super(context, name, factory, version);
    }

    public void onCreate(SQLiteDatabase db, String createSQL) {
        db.execSQL(createSQL);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(HomeRecommendTable.sql);
        db.execSQL(HomeHottestTable.sql);
        db.execSQL(HomeNewestTable.sql);
        db.execSQL(RankingAllTable.sql);
        db.execSQL(RankingGameTable.sql);
        db.execSQL(RankingAppTable.sql);
        db.execSQL(TypeAllTable.sql);
        db.execSQL(TypeGameTable.sql);
        db.execSQL(TypeAppTable.sql);
        db.execSQL(AppInfoTable.sql);
        db.execSQL(ScreenshotTable.sql);
        db.execSQL(MessageTable.sql);
    }

    /**
     * 更新表
     */
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        try {
            db.execSQL("drop table " + HomeRecommendTable.TABLE_NAME);
            db.execSQL("drop table " + HomeHottestTable.TABLE_NAME);
            db.execSQL("drop table " + HomeNewestTable.TABLE_NAME);
            db.execSQL("drop table " + RankingAllTable.TABLE_NAME);
            db.execSQL("drop table " + RankingGameTable.TABLE_NAME);
            db.execSQL("drop table " + RankingAppTable.TABLE_NAME);
            db.execSQL("drop table " + TypeAllTable.TABLE_NAME);
            db.execSQL("drop table " + TypeGameTable.TABLE_NAME);
            db.execSQL("drop table " + TypeAppTable.TABLE_NAME);
            db.execSQL("drop table " + AppInfoTable.TABLE_NAME);
            db.execSQL("drop table " + ScreenshotTable.TABLE_NAME);
            db.execSQL("drop table " + MessageTable.TABLE_NAME);
            onCreate(db);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
